<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="客户编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['customerCode']" placeholder="请输入客户编码"></a-input>
        </a-form-item>
        <a-form-item label="集研编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['researchCode']" placeholder="请输入集研编码"></a-input>
        </a-form-item>
        <a-form-item label="测试工位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-multi-select-tag type="checkbox" v-decorator="['testStation']" :trigger-change="true" dictCode="test_station" placeholder="请选择测试工位"/>
        </a-form-item>
        <a-form-item label="发生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择发生日期" v-decorator="['happenDate']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="不合格现象" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['unqualifiedPhenomenon']" rows="4" placeholder="请输入不合格现象"/>
        </a-form-item>
        <a-form-item label="测试人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['firstTestPersonnel']" placeholder="请输入测试人员"></a-input>
        </a-form-item>
        <a-form-item label="不合格原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['unqualifiedReason']" rows="4" placeholder="请输入不合格原因"/>
        </a-form-item>
        <a-form-item label="维修方案" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['repairProgramme']" rows="4" placeholder="请输入维修方案"/>
        </a-form-item>
        <a-form-item label="维修人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['repairPersonnel']" placeholder="请输入维修人员"></a-input>
        </a-form-item>
        <a-form-item label="维修完成后在测试结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['retestResults']" rows="4" placeholder="请输入维修完成后在测试结果"/>
        </a-form-item>
        <a-form-item label="测试人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['retestPersonnel']" placeholder="请输入测试人员"></a-input>
        </a-form-item>
        <a-form-item label="对应条码(S)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['correspondingBarcode']" placeholder="请输入对应条码(S)"></a-input>
        </a-form-item>
        <a-form-item label="确认人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['confirmationPersonnel']" placeholder="请输入确认人员"></a-input>
        </a-form-item>
        <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['status']" :trigger-change="true" dictCode="unqualified_repair_card" placeholder="请选择状态"/>
        </a-form-item>
        <a-form-item label="制令单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['commandbillCode']" placeholder="请输入制令单号"></a-input>
        </a-form-item>
        <a-form-item label="生产订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['produceId']" placeholder="请输入生产订单ID"></a-input>
        </a-form-item>
        <a-form-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['type']" :trigger-change="true" dictCode="repair_type" placeholder="请选择类型"/>
        </a-form-item>
        <a-form-item label="班别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['classType']" placeholder="请输入班别"></a-input>
        </a-form-item>
        <a-form-item label="线别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['lineType']" placeholder="请输入线别"></a-input>
          <!--<j-dict-select-tag type="list" v-decorator="['lineType']" :trigger-change="true" dictCode="mgroup_code" placeholder="请选择线别"/>-->
        </a-form-item>
        <a-form-item label="站别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['standType']" placeholder="请输入站别"></a-input>
        </a-form-item>
        <a-form-item label="机型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['model']" placeholder="请输入机型"></a-input>
        </a-form-item>
        <a-form-item label="不良数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['badQuantity']" placeholder="请输入不良数量" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JMultiSelectTag from "@/components/dict/JMultiSelectTag"
  
  export default {
    name: "ZsUnqualifiedRepairCardModal",
    components: { 
      JDate,
      JDictSelectTag,
      JMultiSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/inspect/zsUnqualifiedRepairCard/add",
          edit: "/inspect/zsUnqualifiedRepairCard/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'customerCode','researchCode','testStation','happenDate','unqualifiedPhenomenon','firstTestPersonnel','unqualifiedReason','repairProgramme','repairPersonnel','retestResults','retestPersonnel','correspondingBarcode','confirmationPersonnel','status','commandbillCode','produceId','type','classType','lineType','standType','model','badQuantity'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'customerCode','researchCode','testStation','happenDate','unqualifiedPhenomenon','firstTestPersonnel','unqualifiedReason','repairProgramme','repairPersonnel','retestResults','retestPersonnel','correspondingBarcode','confirmationPersonnel','status','commandbillCode','produceId','type','classType','lineType','standType','model','badQuantity'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>